package util;

import java.util.*;

import exception.MethodNotFinishedException;

import statement.Statement;
import util.Type;
import util.Reference;
import util.Class;

public class Method {
	//Chyba jeszcze potrzebne wiele rzeczy w tym
	//przynależność do klasy
	//zebranie Statementow
	private Type returnType;
	private String name;
	private ArrayList<Statement> commandList;
	private Map<String, Attribute> variableMap;
	private boolean isFinished;
	private Result result;
	private Class ownerClass;
	
	public Method(Class ownerClass, Type returnType, String name, List<Attribute> argumentsList, List<Attribute> declarations, List<Statement> statementList) {
		
		this.ownerClass = ownerClass;
		this.returnType = returnType;
		this.name = name;
		isFinished = false;
		commandList = new ArrayList<Statement>();
		variableMap = new HashMap<String, Attribute>();
		
		/*    	ZMIENILEM VARIABLE NA ATTRIBUTE W LISCIE ARGUMENTOW	
		
		for(Variable var:argumentsList){
			if(variableMap.containsKey(var.getName())){
				//TODO blad jakis wywalic
			}
			variableMap.put(var.getName(), var);
		}
		
		*/
		
		for(Statement statement : statementList) {
			commandList.add(statement);
		}
	}
	
	public Type getType() {
		return returnType;
	}
	
	public String getTypeName() {
		return returnType.toString();
	}
	
	public String getMethodName() {
		return name;
	}
	
	public void progress() {
		
	}
	
	public Result getResult() throws MethodNotFinishedException {
		if(!isFinished) {
			throw new MethodNotFinishedException("Metoda " + this.getMethodName() + " jeszcze nie zakonczyla sie");
		}
		return result;
	}
}
